package cn.bx.bid.service;

import cn.bx.bid.dao.UserDao;
import cn.bx.bid.entity.Page;
import cn.bx.bid.entity.User;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

//M V C
@Service
@Scope("prototype")
public class UserService {
	public static final int PAGE_SIZE = Page.PAGE_SIZE;
	@Resource
	private UserDao userDao;
	public int add(User u) {
			return userDao.add(u);

	}
	public int update(User u) {
			return userDao.update(u);

	}
	@Transactional(readOnly=false)
	public int batchDel(long[] ids) {

			return userDao.batchDel(ids);

	}


	public Page<User> paging(int pageNo, int limit, String name, Date start, Date end) {
			List<User> list = userDao.search(pageNo, limit, name, start, end);
			int total = userDao.searchTotal(name, start, end);
			Page<User> p = new Page<User>(total, limit, list);
			return p;
	}

	public User get(long id) {
			return userDao.get(id);


	}

    public boolean checkUserNameRepeat(Long id, String name) {
			return userDao.checkUserNameRepeat(id,name)>0;


    }

    public User login(String username, String password) {
			return userDao.login(username,password);
    }


}
